def test_method(nums, n, k):
    def is_right(nums, k, s, e):
        # [s, e)
        for i in range(s, e):
            if nums[i] > k:
                return False 
            if i > s and nums[i] < nums[i-1]:
                return False
        return True 

    lenn = len(nums)
    count = 0
    for s in range(lenn - n + 1):
        e = s + n
        if is_right(nums, k, s, e):
            count += 1
    return count


def method(nums, n, k):
    s = 0
    e = -1

    count = 0
    while e < len(nums) - 1:
        e += 1
        # print(s, e, f'nums:{nums[s:e+1]}')
        # 降序
        if e > 0 and nums[e] < nums[e - 1]:
            s = e
        # 太大
        if nums[e] > k:
            s = e + 1
        if e - s + 1 == n:
            # print(f'nums:{nums[s:e')
            count += 1
            s += 1
    return count 


from random import randint
def compare(times):
    for _ in range(times):
        n = randint(1, 5)
        lenn = randint(n, 10)

        k = randint(0, 10)
        nums = [randint(-10, 20) for _ in range(lenn)]

        r1 = method(nums, n, k)
        r2 = test_method(nums, n, k)
        
        # print(r1, r2)
        # print(f'n:{n}, k:{k}, nums:{nums}')
        if r1 != r2:
            print('[error]', r1, r2)
            print(f'n:{n}, k:{k}, nums:{nums}')


compare(1000)
